//
//  YYEIntrolFirstCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/3.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEIntrolFirstCell.h"

@interface YYEIntrolFirstCell ()

@property (nonatomic,strong) UIImageView *backIV;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *numLabel;
@property (nonatomic,strong) UILabel *countLabel;
@property (nonatomic,strong) UIButton *placeBtn;
@property (nonatomic,strong) UILabel *placeLabel;

@end

@implementation YYEIntrolFirstCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.backgroundColor = GeneralBackColor;
        
        self.backIV = [[UIImageView alloc]init];
        self.backIV.image = [UIImage imageNamed:@"allBorder"];
        [self.contentView addSubview:self.backIV];
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self.backIV addSubview:self.nameLabel];
        
        self.numLabel = [[UILabel alloc]init];
        self.numLabel.textColor = LineColor;
        self.numLabel.font = [UIFont systemFontOfSize:13];
//        self.numLabel.backgroundColor = [UIColor redColor];
        [self.backIV addSubview:self.numLabel];
        
        self.countLabel = [[UILabel alloc]init];
        self.countLabel.textColor = LineColor;
        self.countLabel.font = [UIFont systemFontOfSize:13];
//        self.countLabel.backgroundColor = [UIColor greenColor];
        [self.backIV addSubview:self.countLabel];
        
        
        self.placeBtn = [UIButton buttonWithframe:CGRectZero text:@"" font:self.countLabel.font textColor:@"#000000" backgroundColor:nil normal:@"定位" selected:nil];
        [self.backIV addSubview:self.placeBtn];

        
        self.placeLabel = [[UILabel alloc]init];
        self.placeLabel.textColor = [UIColor blackColor];
        self.placeLabel.font = [UIFont systemFontOfSize:13];
        //        self.countLabel.backgroundColor = [UIColor greenColor];
        [self.backIV addSubview:self.placeLabel];
//        self.nameLabel.text = @"ava基础入门阶段（javase教程，零基础java入门教程）";
//        self.numLabel.text = @"26课时";
//        self.countLabel.text = @"92人购买";
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.backIV makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(10, 8, 10, 8));
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(10);
        make.right.equalTo(self.backIV.right).offset(-10);
        make.top.equalTo(self.backIV.top).offset(10);
    }];
    
    [self.numLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backIV.left).offset(10);
        make.bottom.equalTo(self.backIV.bottom).offset(-10);
    }];
    
    [self.countLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numLabel.right).offset(20);
        make.bottom.equalTo(self.backIV.bottom).offset(-10);
    }];
    
    [self.placeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numLabel.right).offset(20);
        make.bottom.equalTo(self.backIV.bottom).offset(-10);
        make.size.equalTo(CGSizeMake(13, 15));

    }];
    
    [self.placeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.placeBtn.right).offset(12);
        make.bottom.equalTo(self.backIV.bottom).offset(-10);
    }];
    
}

- (void)setModel:(YYECourseIntroModel *)model {
    _model = model;
    
    self.nameLabel.text = model.title;
    if (model.buys.length > 0) {
        
        self.placeBtn.hidden = YES;
        self.placeLabel.hidden = YES;
        self.countLabel.hidden = NO;

        self.numLabel.textColor = LineColor;
        self.numLabel.text = [NSString stringWithFormat:@"课时%@",model.nums];
//        self.countLabel.text = [NSString stringWithFormat:@"%@人购买",model.buys];
    }
    else {
        
        self.placeBtn.hidden = NO;
        self.placeLabel.hidden = NO;
        self.countLabel.hidden = YES;

        self.numLabel.textColor = [UIColor blackColor];
        self.numLabel.text = model.start_time;
        self.placeLabel.text = model.place;
    }

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
